#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>

#include "cutils/properties.h"
#include "modemcontrol.h"
#include "modem_power.h"

int modem_power_on()
{
    int fd = open(HW_MODEM_DEV, O_RDWR);

    if (fd > 0)
    {
        ioctl(fd, MODEM_PWR_ON);
        close(fd);

        return 1;
    }

    return 0;
}

int modem_power_reset()
{
    int fd = open(HW_MODEM_DEV, O_RDWR);

    if (fd > 0)
    {
        ioctl(fd, MODEM_RESET);
        close(fd);

        return 1;
    }

    return 0;
}

int modem_power_off()
{
    int fd = open(HW_MODEM_DEV, O_RDWR);

    if (fd > 0)
    {
        ril_close_port();

        ioctl(fd, MODEM_PWR_OFF);
        close(fd);
        
		return 1;
    }

    return 0;
}

static void get_baseband_name(char* modem)
{
	property_get("ro.baseband", modem, "");
}

/*
int main(int argc, char** argv)
{
	char baseband[PROPERTY_VALUE_MAX] = {0};
	get_baseband_name(baseband);
	if (strcmp(baseband, MODEM_MU509) == 0)
	{
		modem_power_reset();
	}
	// add more modem type here
	
	return 0;
}
*/
